Skip to content

fix(seed): make seed-sudan-cities work with Prisma 7.x adapters#33

Merged
abdout merged 1 commit into
mainfrom
fix/seed-sudan-prisma-adapter
May 10, 2026
Merged

fix(seed): make seed-sudan-cities work with Prisma 7.x adapters#33
abdout merged 1 commit into
mainfrom
fix/seed-sudan-prisma-adapter

Conversation

@abdout
Copy link
Copy Markdown
Contributor

@abdout abdout commented May 10, 2026

Reproduces the fixes I made on-the-fly while seeding prod (which is now live with 42 new Sudan-city listings).

Why this PR exists

PR #23 added the seed script. Running it on this machine against prod hit two issues:

  1. Prisma 7.x rejects bare new PrismaClient() — it requires an adapter or accelerateUrl.
  2. ES import hoisting@/lib/db is imported and runs its module-level createPrismaClient() before dotenv.config() runs in the function body, so DATABASE_URL is empty when the adapter is constructed.

Fixes

-import { config } from "dotenv";
-config();
+// Side-effect entry — runs config() at module-load time, before
+// the @/lib/db import below resolves and reads process.env.
+import "dotenv/config";

 import {
-  PrismaClient,
   PropertyType, ...
 } from "@prisma/client";
-const prisma = new PrismaClient();
+// Reuse the app's adapter-aware client.
+import { db as prisma } from "@/lib/db";

How to run after this lands

DATABASE_URL_ADAPTER=neon FORCE_SEED=1 pnpm seed:sudan

(FORCE_SEED=1 overrides the NODE_ENV=production guard. DATABASE_URL_ADAPTER=neon selects the HTTPS-tunneled Neon driver.)

Receipt

The pre-fix-script run that produced this PR's content created 42 listings across 7 Sudanese cities in prod (Khartoum, Omdurman, Bahri, Wad Madani, Atbara, Kassala, Nyala) — the autocomplete now returns city diversity:

$ curl -s 'https://mk.databayt.org/api/search/locations?q=Khartoum'
[Bahri, Khartoum (6), Khartoum, Khartoum (6), Omdurman, Khartoum (6)]

$ curl -s 'https://mk.databayt.org/api/search/locations?q=darfur'
[Nyala, South Darfur (6)]

🤖 Generated with Claude Code

Two issues needed fixing to actually run the script against the live
Neon DB (which is what just produced the 42 listings now in prod):

1. Prisma 7.x rejects 'new PrismaClient()' with no options — it
   requires either an adapter or accelerateUrl. The fix: import
   the app's existing 'db' from '@/lib/db', which already wires up
   PrismaPg / PrismaNeon based on DATABASE_URL_ADAPTER.

2. ES module imports are hoisted and execute in source order. If
   '@/lib/db' is imported before dotenv runs, its module-level
   'createPrismaClient()' reads an empty process.env and can't find
   DATABASE_URL. Switch to 'import "dotenv/config"' as a
   side-effect entry — it runs config() at module-load time, so
   DATABASE_URL is set by the time any other import resolves.

Run as: DATABASE_URL_ADAPTER=neon FORCE_SEED=1 pnpm seed:sudan

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mkan Ready Ready Preview, Comment May 10, 2026 7:08am

@abdout abdout merged commit 91cd11c into main May 10, 2026
8 checks passed
@abdout abdout deleted the fix/seed-sudan-prisma-adapter branch May 10, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant